package com.tc.zookeeper.curator;

import com.tc.zookeeper.ZKConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

public class MetricNodeCacheListener extends AbstractEnhancedNodeCacheListener {

	private static Logger LOGGER = LoggerFactory.getLogger(MetricNodeCacheListener.class);

	private EnhancedNodeCache nodeCache;

	private Map<String, String> zkVersionMap;

	private Map<String, String> zkContentMap;

	private String connStr;

	private String path;

	public MetricNodeCacheListener(EnhancedNodeCache nodeCache, String targetConnectString) {
		super();
		this.nodeCache = nodeCache;
		this.connStr = targetConnectString;
		String fullPath = null;
		try {
			path = nodeCache.getCurrentData().getPath();
			String content = new String(nodeCache.getCurrentData().getData(), ZKConstants.DEFAULT_CHARSET);
			String version = nodeCache.getCurrentData().getStat().getVersion() + "";

			EnhancedCuratorFramework client = EnhancedCuratorFrameworkFactory.getStartedClientByConnectString(connStr);
			fullPath = client.getNamespace() + path;
			/*zkVersionMap = MetricRegister.getZkVersionMap(fullPath, connStr, version);
			MetricRegister.registerStaticNodeVersion(fullPath, zkVersionMap);

			zkContentMap = MetricRegister.getZkContentMap(fullPath, content, connStr, version);
			MetricRegister.registerInternalNodeContent(fullPath, zkContentMap);*/
		} catch (Exception e) {
			LOGGER.error("MetricNodeCacheListener constructor, " + e.getMessage() + ", zkpath=" + fullPath);
		}
	}

	@Override
	public void doNodeChanged() {
		try {
		/*	String data = new String(nodeCache.getCurrentData().getData(), ZKConstants.DEFAULT_CHARSET);
			String version = nodeCache.getCurrentData().getStat().getVersion() + "";
			MetricRegister.updateNodeVersionMap(version, zkVersionMap);

			MetricRegister.updateNodeContentMap(data, version, zkContentMap);*/
			// LOGGER.info("doNodeChanged>>>>>>>>>>version:" + version);
		} catch (Exception e1) {
			LOGGER.error("doNodeChanged getCurrentData error:" + e1.getMessage());
		}

	}

}
